<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>龙回头</title>
<style type="text/css">
table.gridtable {
	font-family: verdana, arial, sans-serif;
	font-size: 11px;
	color: #333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}

table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}

table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}

tr:hover td {
	background: none;
}

tr:hover {
	background-color: none;
}

thead th {
	position: sticky;
	top: 0;
	z-index: 1;
}

table {
	border-collapse: collapse;
	width: 100%;
}

th, td {
	padding: 8px;
	text-align: left;
}

th {
	background-color: #f2f2f2;
}

#myDiv { 
	background-color: #f1f1f1;
	padding: 10px;
}
 .popup {
      width: 1000px;
      height: 700px;
      background-color: #f1f1f1;
      border: 1px solid #ccc;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    .close-btn {
      position: absolute;
      top: 0;
      right: 0;
      padding: 10px;
      cursor: pointer;
      font-size: 20px;
      color: #aaa;
    }
</style>
<meta charset="UTF-8">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/grid1.0.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
</head> 
<body>

	<input  id="text1"></input>
	<button id="bt12">龙回头</button>
	<button id="bt13">概念查询（只查有过内容content）</button> 
	<div id="div1"></div>
	<div id="myDiv"></div>
	<div class="popup" style="display:none;overflow-y:auto; ">
<!-- 这里可以添加你的内容 --> <span class="close-btn" id="san1">×</span>
   <div style="width:1000px;height:800px;margin-top: 40px;" id="mainechar">
   
   </div>
 
	 </div>
	 
<script type="text/javascript">

(function(){
	 
		var arrall = [];
		$("#bt13").click(function(){
			arrall = [];
			$("#div1").html("");
			 $('table td[name=ztContent]:not(:first)').each(function() {
			    var content = $(this).text();
			    var temp = content.split(",");
			    arrall =$.merge(arrall,temp);
			    
			    var text1 = $("#text1").val().replace("+","_").split(",");
			    var flag = true;
			    
			     if(text1.length==1){
			    	 if(content.includes(text1)){
			    		
			    	 }else{
			    		 $(this).parent().hide();
			    	 }
			     } 
			     if(text1.length==2){
			    	 if(content.includes(text1[0]) && content.includes(text1[1]) ){
			    		 
			    	 } else{
			    		 $(this).parent().hide();
			    	 }
			     }
			     if(text1.length==3){
			    	 if(content.includes(text1[0]) && content.includes(text1[1])&& content.includes(text1[2]) ){
			    		 
			    	 }else{
			    		 $(this).parent().hide();
			    	 }
			     } 
			  });  
			 var countMap = {};
			 for (var i = 0; i < arrall.length; i++) {
			   var num = arrall[i];
			   if (countMap[num]) {
			     countMap[num]++;
			   } else {
			     countMap[num] = 1;
			   }
			 }

			 var sortedCountMap = Object.entries(countMap).sort((a, b) => b[1] - a[1]);
			 var i=0;
			 for (var [num, count] of sortedCountMap) {
			     i++;
			   console.log(num + ": " + count);
			   $("#div1").append("<lable>"+num+"("+count+")"+"</lable>");
			   if(i>10){
				   break;
			   }
			 }
		}); 
		$("#bt14").click(function(){ 
			var result = [];
			$('table tr:not(:first)').each(function() {
			    var rowObject = {};
			    $(this).find('td').each(function() {
			        var name = $(this).attr('name');
			        if(typeof(name)=='undefind'){
			        	return;
			        }
			        if(name=="name"){
			        	rowObject.name = $(this).text();
			        }else if(name=="pl_content"){
			        	rowObject[name] = $(this).children().val();
			        }else{
			        	rowObject[name] = $(this).attr(name);
			        }
			        
			    });
			    result.push(rowObject);
			});
			
			console.log(result);
			
			 $.ajax({
				type : "post",
				url : "${pageContext.request.contextPath}/addModelContent2jin3",
				dataType : 'text',
				data:{arr:JSON.stringify(result)},
				success : function(msg) {
					 
					 alert(msg);
				}
			});
			
			
			
		});
	
	 

	 $(".close-btn").click(function () {
	      $(".popup").hide();
	    });
	$("#bt12").click(function(){
		$("#myDiv").html("");
	//	setCookie("allcodeMy",$("#textarea1").val(),1000);
		
		 $.ajax({
				type : "get",
				url : "${pageContext.request.contextPath}/getLonghuitou",
				dataType : 'text',
				//data:{textarea1:$("#textarea1").val()},
				success : function(msg) {  
					$("#myDiv").html(msg);
					$("#mytalbe").addClass("gridtable"); 
					$('td[name="pl_content"]:not(:first)').each(function() {
					    var content = $(this).html();
					    var input = $('<textarea  style="width:200px;height:50px;" value="' + content + '" />');
					    $(this).html(input);
					    $(input).val(content);
					});
				 
					tongyong();
				}
			});
		 
		 
	 }); 
	function tongyong(){
		 $("#mytalbe td[name=shizhi]:not(:first)").each(function(){
		        var num = parseFloat($(this).text()); 
		        var roundedNum = num.toFixed(2);
		        $(this).text(roundedNum);
		 });
		 $("#mytalbe td[name=ji20min]:not(:first)").each(function(){
		        var num = parseFloat($(this).text()); 
		        var roundedNum = num.toFixed(2);
		        $(this).text(roundedNum);
		 });
		 $("#mytalbe td[name=table_id]").each(function(){ 
		        $(this).hide();
		 });
		 $("#mytalbe td[name=lt]").each(function(){ 
		        $(this).hide();
		 });
		 $("#mytalbe td[name=createTime]").each(function(){ 
		        $(this).hide();
		 });
		 $("#mytalbe td[name=cjllist]").each(function(){ 
		        $(this).hide();
		 });
		 $("#mytalbe td[name=qy]").each(function(){ 
		        $(this).hide();
		 });
		 $("#mytalbe td[name=jgbi]:not(:first)").each(function(){ 
			 var num = parseFloat($(this).text()); 
		        var roundedNum = num.toFixed(2);
		        $(this).text(roundedNum);
		 });
		 $("#mytalbe td[name=cjlsum]:not(:first)").each(function(){ 
			 var num = parseFloat($(this).text()); 
		        var roundedNum = num.toFixed(2);
		        $(this).text(roundedNum);
		 });
		 $('#mytalbe').each(function() {
			  var rows = $(this).find('tr:not(:first)');
			  rows.sort(function(a, b) {
			    var aValue = $(a).find('td[name=ji20min]').text();
			    var bValue = $(b).find('td[name=ji20min]').text();
			    return aValue.localeCompare(bValue);
			  });
			  $(this).append(rows);
			});
		 $("#mytalbe td[name=code]").click(function(){  
		        $(".popup").show();
		        var c = $(this).parent().find("td[name=cjllist]").attr("cjllist");
		        var temp = $.parseJSON(c);
		        var name = $(this).parent().find("td[name=name]").html();
		        $("#san1").html("x"+name);
		       // loadechar(temp); 
		 }); 
		 $('table tbody tr').sort(function(a, b) {
		        return parseInt($('td[name=count]', b).text()) - parseInt($('td[name=count]', a).text());
		    }).appendTo('table tbody');
	}
	function loadechar(list){ 
		var arr1 = [];
		var arr2 = [];
		var arr3 = [];
		var arr4 = [];
		var count=0;
		for(var i=list.length-1;i>=0;i--){
			arr1.push(list[i].date.substring(4,8));
			arr2.push(list[i].huanshoulv);
			if(list[i].huanshoulv!=null){
				count+=parseFloat(list[i].huanshoulv);
			}
			arr3.push(count.toFixed(2));
			arr4.push(list[i].zhandifu);
		}
		 
		var chartDom = document.getElementById('mainechar');
		var myChart = echarts.init(chartDom);
		var option; 
		option = {
		  tooltip: {
		    trigger: 'axis',
		    axisPointer: {
		      type: 'cross',
		      crossStyle: {
		        color: '#999'
		      }
		    }
		  },
		  toolbox: {
		    feature: {
		      dataView: { show: true, readOnly: false },
		      magicType: { show: true, type: ['line', 'bar'] },
		      restore: { show: true },
		      saveAsImage: { show: true }
		    }
		  },
		  legend: {
		    data: ['Precipitation', 'Temperature']
		  },
		  xAxis: [
		    {
		      type: 'category',
		      data: arr1,
		      axisPointer: {
		        type: 'shadow'
		      }
		    }
		  ],
		  yAxis: [
		    {
		      type: 'value',
		      name: '日期',
		      min: 0,
		      max: 300,
		      interval: 50,
		      axisLabel: {
		        formatter: '{value} ml'
		      }
		    }
		  ],
		  series: [
		    {
		      name: '成交总量',
		      stack: 'showAllSymbol',
		      type: 'line',
		      label: {
		          show: true,
		          position: 'top'
		        },
		      data:arr3
		    },
		    {
		      name: 'Precipitation',
		      type: 'bar',
		      label: {
		          show: true,
		          position: 'top'
		        },
		      data: arr2
		    } 
		  ]
		}; 
		option && myChart.setOption(option);
	} 
	//设置cook
	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date()
		exdate.setDate(exdate.getDate()+expiredays)
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
		} 
		function checkCookie()
		{
		username=getCookie('username')
		if (username!=null && username!="")
		  {alert('Welcome again '+username+'!')}
		else 
		  {
		  username=prompt('Please enter your name:',"")
		  if (username!=null && username!="")
		    {
		    setCookie('username',username,365)
		    }
		  }
	}
	function getCookie(cookieName) {
	    const name = cookieName + "=";
	    const decodedCookie = decodeURIComponent(document.cookie);
	    const cookieArray = decodedCookie.split(';');
	    
	    for (let i = 0; i < cookieArray.length; i++) {
	        let cookie = cookieArray[i].trim();
	        if (cookie.indexOf(name) === 0) {
	            return cookie.substring(name.length);
	        }
	    }
	    return "";
	}
})();
</script>
</body>
</html>